package com.tianqu.tms.www.cardect.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.www.cardect.actionform.TisDetectSeniorActionForm;
import com.tianqu.tms.www.cardect.viewhelper.CarSeniorDetectViewHelper;
/**
 * 进入到高级检测首页按钮分发action
 * 
 * @author tianshifu
 *
 */
public class CarWCSeniorDetectTopDispatchAction extends TmsAction {
	private Logger logger = Logger.getLogger(CarWCSeniorDetectTopDispatchAction.class);//log
	private static final String DETECT_POSITION = "detect_position";//检测位置，标识哪个button提交
	private static final String SENIOR_DETECT_INPUT_DATA = "senior_detect_input_data";//检测录入信息
	private static final String SAVE_STATUS = "save_status";//保存状态
	private static final String IMGKEY = "imgKey";// 图片位置
	private static final String IMGTYPE = "imgType";// 图片类型
	private static final String CHKMODEL = "chkModel";//检测模式	
	
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");	
		
		TisDetectSeniorActionForm seniorForm = (TisDetectSeniorActionForm)form;
		
		//根据从页面获取的按钮来选择进入哪个action处理
		String actionForward = "";

		if(seniorForm.getSeniorToNormalDetectButton()!=null)// 模式切换按钮
		{
			actionForward = "seniorToNormalForward";//跳转到检测信息录入页面			
		}
		/***车辆整体六张图****/
		if(seniorForm.getZqButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "1");
			uc.setAttribute(CHKMODEL, "2");
			actionForward = "seniorDetectImageForward";//跳转到图片上传	
		}
		if(seniorForm.getYhButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "2");
			uc.setAttribute(CHKMODEL, "2");
			actionForward = "seniorDetectImageForward";
		}
		if(seniorForm.getFdjcButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "3");
			uc.setAttribute(CHKMODEL, "2");
			actionForward = "seniorDetectImageForward";
		}
		if(seniorForm.getYbpButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "4");
			uc.setAttribute(CHKMODEL, "2");
			actionForward = "seniorDetectImageForward";
		}
		if(seniorForm.getQpButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "5");
			uc.setAttribute(CHKMODEL, "2");
			actionForward = "seniorDetectImageForward";
		}
		if(seniorForm.getHpButton()!=null)
		{
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "6");
			uc.setAttribute(CHKMODEL, "2");
			actionForward = "seniorDetectImageForward";
		}		
		if(seniorForm.getAccidentButton()!=null)// 事故检测
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "1");
			actionForward = "seniorDetectDataInput";//跳转到检测信息录入页面					
		}
		if(seniorForm.getCarOutwardButton()!=null)// 技术检测 - 车身外观录入
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "2");
			actionForward = "seniorDetectDataInput";//跳转到检测信息录入页面				
		}
		if(seniorForm.getCarEngineButton()!=null)//技术检测 - 发动机舱录入
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "3");
			actionForward = "seniorDetectDataInput";//跳转到检测信息录入页面			
		}
		if(seniorForm.getCarPilotButton()!=null)// 技术检测 - 驾驶舱录入
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "4");
			actionForward = "seniorDetectDataInput";//跳转到检测信息录入页面		
		}
		if(seniorForm.getCarStartButton()!=null)// 技术检测 - 启动录入
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "5");
			actionForward = "seniorDetectDataInput";//跳转到检测信息录入页面		
		}
		if(seniorForm.getCarRunButton()!=null)// 技术检测 - 路试录入
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "6");
			actionForward = "seniorDetectDataInput";//跳转到检测信息录入页面		
		}
		if(seniorForm.getCarBottomButton()!=null)// 技术检测 - 底盘录入
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "7");
			actionForward = "seniorDetectDataInput";//跳转到检测信息录入页面		
		}
		if(seniorForm.getCarDiscribeButton()!=null)// 检测说明录入
		{
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "8");
			actionForward = "seniorDetectDataInput";//跳转到检测信息录入页面		
		}
		if(seniorForm.getCarDetectSaveButton()!=null)// 提交
		{
			actionForward = "seniorDetectDataSubmitConfirm";//跳转到提交确认页	
			uc.setAttribute(SAVE_STATUS, "6");//确认完了			
		}
		if(seniorForm.getCarDetectNowSaveButton()!=null)// 保存
		{
			actionForward = "seniorDetectDataSubmitConfirm";//跳转到暂时保存确认页	
			uc.setAttribute(SAVE_STATUS, "3");//待检测人工			
		}
		//需要将页面的信息取出来放到uc中供返回的时候调用 （只set配置信息 表显里程整车检测）
		//每次跳转前都需要将页面的信息获取放到uc中供返回的时候读取
		CarSeniorDetectViewHelper view = new CarSeniorDetectViewHelper();
		if(uc.getAttribute(SENIOR_DETECT_INPUT_DATA)!=null)
		{
			view = (CarSeniorDetectViewHelper)uc.getAttribute(SENIOR_DETECT_INPUT_DATA);
		}	
		view.setMileage(seniorForm.getMileage());//表显里程
		uc.removeAttribute(SENIOR_DETECT_INPUT_DATA);
		uc.setAttribute(SENIOR_DETECT_INPUT_DATA, view);
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(actionForward);
	}

}
